package org.shagin.jfin.date.cond;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.shagin.jfin.core.CoreUtils;

/**
 * The Class DateConditionSet.
 */
@SuppressWarnings("serial")
public class DateConditionSet implements IDateCondition {

    private DateRange range = new DateRange();
    private List<IDateCondition> yepList = new ArrayList<IDateCondition>();
    private List<IDateCondition> notList = new ArrayList<IDateCondition>();

    /**
     * Instantiates a new date condition set.
     */
    public DateConditionSet() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean validDate(Date date) {

        boolean result = false;
        for (IDateCondition dateCondition : yepList) {
            if (dateCondition.validDate(date)) {
                result = true;
                break;
            }
        }

        if (result) {
            for (IDateCondition dateCondition : notList) {
                if (dateCondition.validDate(date)) {
                    result = false;
                    break;
                }
            }
        }

        return result;
    }

    /**
     * Adds the yep.
     *
     * @param dateCondition the date condition
     */
    public void addYep(IDateCondition dateCondition) {
        yepList.add(dateCondition);
    }

    /**
     * Adds the not.
     *
     * @param dateCondition the date condition
     */
    public void addNot(IDateCondition dateCondition) {
        notList.add(dateCondition);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public DateRange getRange() {
        return range;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String format() {
        CoreUtils.notImplemented();
        return null;
    }
}
